package edu.ncsu.csc.sensors;

import java.io.IOException;

import com.sun.spot.sensorboard.EDemoBoard;
import com.sun.spot.sensorboard.io.IScalarInput;

/**
 * Reads from the  
 * 
 * @author Douglas McClusky, David A Boyuka II
 */
public class StrainGaugeSensor implements Sensor {
    private static final int MAX_VOLTAGE_MILLIVOLTS = 3300;
    private static final int MAX_VALUE = 1024;
    private static final double GAUGE_FACTOR = 0.232; // Not used here, use for calculations on server
    
    private IScalarInput input;

    public StrainGaugeSensor() {
    	this(EDemoBoard.A0);
    }
    
    public StrainGaugeSensor(int analogPin) {
    	input = EDemoBoard.getInstance().getScalarInputs()[analogPin];
    }
    
    public char getValue() {
    	try {
            int millivolts = input.getValue()*0x10000/MAX_VALUE;
            return (char)millivolts;
    	} catch (IOException ioe) {
    		return 0;
    	}
	}
}
